package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.album.service.VodService;
import com.atguigu.tingshu.common.login.Login;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.TrackInfoVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

	@Autowired
	private TrackInfoService trackInfoService;

	@Autowired
	VodService vodService;

	// http://192.168.200.1:8500/api/album/trackInfo/uploadTrack
	@Login
	@PostMapping("/uploadTrack")
	public Result uploadTrack(MultipartFile file){
		Map<String,String>map = vodService.uploadTrack(file);
		return Result.ok(map);
	}

	// Request URL: http://192.168.200.1:8500/api/album/trackInfo/saveTrackInfo
	@PostMapping("/saveTrackInfo")
	@Operation(summary = "保存声音")
	@Login
	public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo) {
		trackInfoService.saveTrackInfo(trackInfoVo);
		return Result.ok();
	}
	// Request URL: http://192.168.200.1:8500/api/album/trackInfo/findUserTrackPage/1/10
	@Login
	@PostMapping("/findUserTrackPage/{pn}/{pz}")
	@Operation(summary = "分页展示上传的声音列表")
	public Result findUserTrackPage(@PathVariable Long pn, @PathVariable Long pz, @RequestBody TrackInfoQuery trackInfoQuery){
		IPage<TrackListVo>page = new Page<>(pn,pz);
		page = trackInfoService.findUserTrackPage(page,trackInfoQuery);
		return Result.ok(page);
	}
	// Request URL: http://192.168.200.1:8500/api/album/trackInfo/removeTrackInfo/51942
	@DeleteMapping("/removeTrackInfo/{trackId}")
	@Operation(summary = "删除声音数据")
	@Login
	public Result removeTrackInfo(@PathVariable(value = "trackId") Long trackId) {
		trackInfoService.removeTrackInfo(trackId);
		return Result.ok();
	}
	// Request URL: http://192.168.200.1:8500/api/album/trackInfo/getTrackInfo/51943
	@GetMapping("/getTrackInfo/{trackId}")
	@Operation(summary = "回显声音数据")
	@Login
	public Result<TrackInfo> getTrackInfo(@PathVariable(value = "trackId") Long trackId) {
		TrackInfo trackInfo = trackInfoService.getTrackInfo(trackId);
		return Result.ok(trackInfo);
	}
	// Request URL: http://192.168.200.1:8500/api/album/trackInfo/updateTrackInfo/51943
	@PutMapping("/updateTrackInfo/{trackId}")
	@Operation(summary = "修改声音数据")
	@Login
	public Result updateTrackInfo(@PathVariable(value = "trackId") Long trackId,
								  @RequestBody TrackInfoVo trackInfoVo) {

		trackInfoService.updateTrackInfo(trackId, trackInfoVo);
		return Result.ok();
	}
	// Request URL: http://192.168.200.1:8500/api/album/trackInfo/findAlbumTrackPage/139/1/10
	@Operation(summary = "分页展示专辑下的声音列表")
	@Login(isLogin = false)  // 不用登录： 但是如果前端带了token 可以的 不带一定拿不到
	public Result findAlbumTrackPage(@PathVariable(value = "albumId") Long albumId,
									 @PathVariable(value = "pn") Long pn,
									 @PathVariable(value = "pz") Long pz) {}
}

